winsafe\dshow\com_interfaces/
ipin.rs

1#![allow(non_camel_case_types, non_snake_case)]
2
3use crate::co;
4use crate::decl::*;
5use crate::dshow::vts::*;
6use crate::kernel::privs::*;
7use crate::ole::privs::*;
8use crate::prelude::*;
9
10com_interface! { IPin: "56a86891-0ad4-11ce-b03a-0020af0ba770";
11	/// [`IPin`](https://learn.microsoft.com/en-us/windows/win32/api/strmif/nn-strmif-ipin)
12	/// COM interface.
13	///
14	/// Automatically calls
15	/// [`IUnknown::Release`](https://learn.microsoft.com/en-us/windows/win32/api/unknwn/nf-unknwn-iunknown-release)
16	/// when the object goes out of scope.
17}
18
19impl dshow_IPin for IPin {}
20
21/// This trait is enabled with the `dshow` feature, and provides methods for
22/// [`IPin`](crate::IPin).
23pub trait dshow_IPin: ole_IUnknown {
24	fn_com_noparm! { BeginFlush: IPinVT;
25		/// [`IPin::BeginFlush`](https://learn.microsoft.com/en-us/windows/win32/api/strmif/nf-strmif-ipin-beginflush)
26		/// method.
27	}
28
29	/// [`IPin::Connect`](https://learn.microsoft.com/en-us/windows/win32/api/strmif/nf-strmif-ipin-connect)
30	/// method.
31	fn Connect(&self, receive_pin: &impl dshow_IPin, mt: Option<&AM_MEDIA_TYPE>) -> HrResult<()> {
32		ok_to_hrresult(unsafe {
33			(vt::<IPinVT>(self).Connect)(self.ptr(), receive_pin.ptr(), pcvoid_or_null(mt))
34		})
35	}
36
37	fn_com_interface_get! { ConnectedTo: IPinVT => IPin;
38		/// [`IPin::ConnectedTo`](https://learn.microsoft.com/en-us/windows/win32/api/strmif/nf-strmif-ipin-connectedto)
39		/// method.
40	}
41
42	/// [`IPin::ConnectionMediaType`](https://learn.microsoft.com/en-us/windows/win32/api/strmif/nf-strmif-ipin-connectionmediatype)
43	/// method.
44	fn ConnectionMediaType(&self, amt: &mut AM_MEDIA_TYPE) -> HrResult<()> {
45		ok_to_hrresult(unsafe { (vt::<IPinVT>(self).ConnectionMediaType)(self.ptr(), pvoid(amt)) })
46	}
47
48	fn_com_noparm! { Disconnect: IPinVT;
49		/// [`IPin::Disconnect`](https://learn.microsoft.com/en-us/windows/win32/api/strmif/nf-strmif-ipin-disconnect)
50		/// method.
51	}
52
53	fn_com_noparm! { EndFlush: IPinVT;
54		/// [`IPin::EndFlush`](https://learn.microsoft.com/en-us/windows/win32/api/strmif/nf-strmif-ipin-endflush)
55		/// method.
56	}
57
58	fn_com_noparm! { EndOfStream: IPinVT;
59		/// [`IPin::EndOfStream`](https://learn.microsoft.com/en-us/windows/win32/api/strmif/nf-strmif-ipin-endofstream)
60		/// method.
61	}
62
63	fn_com_interface_get! { EnumMediaTypes: IPinVT => IEnumMediaTypes;
64		/// [`IPin::EnumMediaTypes`](https://learn.microsoft.com/en-us/windows/win32/api/strmif/nf-strmif-ipin-enummediatypes)
65		/// method.
66	}
67
68	/// [`IPin::NewSegment`](https://learn.microsoft.com/en-us/windows/win32/api/strmif/nf-strmif-ipin-newsegment)
69	/// method.
70	fn NewSegment(&self, start: i64, stop: i64, rate: f64) -> HrResult<()> {
71		ok_to_hrresult(unsafe { (vt::<IPinVT>(self).NewSegment)(self.ptr(), start, stop, rate) })
72	}
73
74	/// [`IPin::QueryAccept`](https://learn.microsoft.com/en-us/windows/win32/api/strmif/nf-strmif-ipin-queryaccept)
75	/// method.
76	#[must_use]
77	fn QueryAccept(&self, amt: &AM_MEDIA_TYPE) -> HrResult<bool> {
78		okfalse_to_hrresult(unsafe { (vt::<IPinVT>(self).QueryAccept)(self.ptr(), pcvoid(amt)) })
79	}
80
81	/// [`IPin::QueryDirection`](https://learn.microsoft.com/en-us/windows/win32/api/strmif/nf-strmif-ipin-querydirection)
82	/// method.
83	#[must_use]
84	fn QueryDirection(&self) -> HrResult<co::PIN_DIRECTION> {
85		let mut pin_dir = co::PIN_DIRECTION::INPUT;
86		ok_to_hrresult(unsafe {
87			(vt::<IPinVT>(self).QueryDirection)(self.ptr(), pvoid(&mut pin_dir))
88		})
89		.map(|_| pin_dir)
90	}
91
92	/// [`IPin::QueryId`](https://learn.microsoft.com/en-us/windows/win32/api/strmif/nf-strmif-ipin-queryid)
93	/// method.
94	#[must_use]
95	fn QueryId(&self) -> HrResult<String> {
96		let mut pstr = std::ptr::null_mut::<u16>();
97		ok_to_hrresult(unsafe { (vt::<IPinVT>(self).QueryId)(self.ptr(), &mut pstr) })
98			.map(|_| htaskmem_ptr_to_str(pstr))
99	}
100
101	/// [`IPin::QueryInternalConnections`](https://learn.microsoft.com/en-us/windows/win32/api/strmif/nf-strmif-ipin-queryinternalconnections)
102	/// method.
103	#[must_use]
104	fn QueryInternalConnections(&self) -> HrResult<Vec<IPin>> {
105		let mut count = 0u32;
106		if let Err(e) = ok_to_hrresult(unsafe {
107			(vt::<IPinVT>(self).QueryInternalConnections)(
108				self.ptr(),
109				std::ptr::null_mut(),
110				&mut count,
111			)
112		}) {
113			return Err(e);
114		}
115
116		let mut queried = vec![unsafe { IPin::null() }];
117		ok_to_hrresult(unsafe {
118			(vt::<IPinVT>(self).QueryInternalConnections)(
119				self.ptr(),
120				queried.as_mut_ptr() as _,
121				&mut count,
122			)
123		})
124		.map(|_| queried)
125	}
126
127	/// [`IPin::QueryPinInfo`](https://learn.microsoft.com/en-us/windows/win32/api/strmif/nf-strmif-ipin-querypininfo)
128	/// method.
129	fn QueryPinInfo(&self, info: &mut PIN_INFO) -> HrResult<()> {
130		ok_to_hrresult(unsafe { (vt::<IPinVT>(self).QueryPinInfo)(self.ptr(), pvoid(info)) })
131	}
132
133	/// [`IPin::ReceiveConnection`](https://learn.microsoft.com/en-us/windows/win32/api/strmif/nf-strmif-ipin-receiveconnection)
134	/// method.
135	fn ReceiveConnection(&self, connector: &impl dshow_IPin, mt: &AM_MEDIA_TYPE) -> HrResult<()> {
136		ok_to_hrresult(unsafe {
137			(vt::<IPinVT>(self).ReceiveConnection)(self.ptr(), connector.ptr(), pcvoid(mt))
138		})
139	}
140}